﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Chronicles_of_Asku.Areas.Tomb_Floors._1_10.ResourceFile;
using The_Chronicles_of_Asku.Characters;

namespace The_Chronicles_of_Asku.Areas.Tomb_Floors._1_10
{
    class FloorTwo
    {
        Battle battle = new Battle();
        Skeleton skel = new Skeleton();
        Necromancer necro = new Necromancer();
        Undead zombie = new Undead();
        SetMobLevels setLevel = new SetMobLevels();
        Hero myHero = new Hero();
        public bool complete = false;

        public void theFloor(Hero myHero, Mob mob)
        {
            setLevel.setMobLevelSix(skel, necro, zombie);

            Console.WriteLine(FloorTwoText.Entrance);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorTwoText.FirstMove);

                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorTwoText.SecondMove);
                string firstAnswer = Console.ReadLine();
                    
                if (firstAnswer == "1")
                {
                    Console.WriteLine(FloorTwoText.ChoseFirstRoomSecondMove);

                    NecromancerFight(myHero, necro);
                    SkeletonFight(myHero, skel);

                    if (myHero.isAlive == true)
                    {
                        Console.WriteLine(FloorTwoText.FirstRoomFinished);
                        string firstRoomClearedQuestion = Console.ReadLine();
                        if (firstRoomClearedQuestion == "1")
                        {
                            Console.WriteLine(FloorTwoText.ChoseSecondRoomSecondMove);
                            string chestAnswer = Console.ReadLine();
                            do 
                            {
                                switch (chestAnswer)
                                {
                                    case "1":
                                        Console.Clear();
                                        Console.WriteLine(FloorTwoText.SecondRoomOpenChest, "\n");
                                        Console.ReadKey();
                                        Console.Clear();
                                        myHero.gold += 100;
                                        if (myHero.gold >= myHero.goldCap)
                                        {
                                            myHero.gold = myHero.goldCap;
                                        }
                                        break;
                                    case "2":
                                        Console.Clear();
                                        Console.WriteLine(FloorTwoText.DontOpenChestSecondRoom);
                                        Console.ReadKey();
                                        Console.Clear();
                                        break;
                                    default:
                                        Console.Clear();
                                        Console.WriteLine("You picked an invalid option. You idiot.");
                                        Console.ReadKey();
                                        Console.Clear();
                                        break;
                                }
                            } while (chestAnswer != "1" && chestAnswer != "2" && myHero.isAlive == true);

                            Console.Clear();
                            Console.WriteLine(FloorTwoText.FirstRoomSecondRoomFinished);
                            Console.ReadKey();
                        }
                    }
                }
                else if (firstAnswer == "2")
                {
                    Console.WriteLine(FloorTwoText.ChoseSecondRoomSecondMove);
                    string chestAnswer = Console.ReadLine();
                    do
                    {
                        switch (chestAnswer)
                        {
                            case "1":
                                Console.Clear();
                                Console.WriteLine(FloorTwoText.SecondRoomOpenChest);
                                Console.ReadKey();
                                Console.Clear();
                                myHero.gold += 100;
                                break;
                            case "2":
                                Console.Clear();
                                Console.WriteLine(FloorTwoText.DontOpenChestSecondRoom);
                                Console.ReadKey();
                                Console.Clear();
                                break;
                            default:
                                Console.Clear();
                                Console.WriteLine("You picked an invalid option. You idiot.");
                                Console.ReadKey();
                                Console.Clear();
                                break;
                        }

                        Console.Clear();
                        Console.WriteLine(FloorTwoText.FinishedSecondRoom);
                        string secondRoomClearedQuestion = Console.ReadLine();
                        if (secondRoomClearedQuestion == "1")
                        {
                            Console.Clear();
                            Console.WriteLine(FloorTwoText.ChoseFirstRoomSecondMove);

                            NecromancerFight(myHero, necro);
                            SkeletonFight(myHero, skel);

                            if (myHero.isAlive == true)
                            {
                                Console.Clear();
                                Console.WriteLine(FloorTwoText.FinishedSecondRoomFirstRoom);
                                Console.ReadKey();
                                Console.Clear();
                            }
                        }
                    } while (chestAnswer != "1" && chestAnswer != "2" && myHero.isAlive == true);
                }

                //Third Room is the one that continues on
            }

            setLevel.setMobLevelSeven(skel, necro, zombie);

            if (myHero.isAlive == true)
            {
                Console.Clear();
                Console.WriteLine(FloorTwoText.ThirdRoom);

                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);

                if (myHero.isAlive == true)
                {
                    Console.Clear();
                    Console.WriteLine(FloorTwoText.ThirdRoomNecrosKilled);

                    UndeadFight(myHero, zombie);
                }
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorTwoText.ThirdRoomFinished);

                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);

                setLevel.setMobLevelEight(skel, necro, zombie);

                NecromancerFight(myHero, necro);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);

                if (myHero.isAlive == true)
                {
                    Console.Clear();
                    Console.WriteLine(FloorTwoText.LargeRoomCompleted);
                    Console.ReadKey();
                    Console.Clear();
                    complete = true;
                }
            }

            if (myHero.isAlive == false)
            {
                Console.Clear();
                Console.WriteLine(FloorTwoText.Dead);
                Console.ReadKey();
                Console.Clear();
                myHero.isAlive = true;
            }
        }

        private void UndeadFight(Hero myHero, Undead zombie)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, zombie);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            zombie.ResetStats(zombie);

            Console.Clear();
        }

        private void SkeletonFight(Hero myHero, Skeleton skel)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, skel);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            skel.ResetStats(skel);

            Console.Clear();
        }

        private void NecromancerFight(Hero myHero, Necromancer necro)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, necro);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            necro.ResetStats(necro);

            Console.Clear();
        }
    }
}
